package cn.wolfcode.wolf2w.job;

import cn.wolfcode.wolf2w.redis.service.IStrategyStatisVORedisService;
import cn.wolfcode.wolf2w.redis.vo.StrategyStatisVO;
import cn.wolfcode.wolf2w.service.IStrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.List;

/**
 * redis数据持久化定时任务
 */
public class RedisDataPersistenceJob {

    @Autowired
    private IStrategyStatisVORedisService strategyStatisVORedisService;
    @Autowired
    private IStrategyService strategyService;
    //@Scheduled :定时任务注解:指定当前方法为定时任务方法
    @Scheduled(cron = "0/5 * * * *?")
    public void doWord() {
        System.out.println("-----------------------");

        //获取所有攻略的统计对象vo集合
       List<StrategyStatisVO> list= strategyStatisVORedisService.queryVoBypattern("*");
        //遍历vo对象,更新MongoDB数据
        for (StrategyStatisVO vo : list) {
            strategyService.updateStatisVo(vo);
        }
    }
}
